// pages/tabBar/home/home.js

const pageInfo = require('../../../common/pageInfo');
const util = require('../../../common/util');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    banner: ["https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "/static/banner_1.jpg",
      "/static/banner_2.jpg",
      "/static/banner_3.jpg"
    ],
    category: ["https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
      "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
    ],
    hotSale: [{
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      }
    ],
    menu: ["全部",
      "分类1",
      "分类2",
      "分类3",
      "分类4",
      "分类5",
      "分类6",
      "分类7",
      "分类8",
      "分类9"
    ],
    categoryGoods: [{
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      },
      {
        path: "https://pic3.zhimg.com/v2-e02412cda298546ebe071b194dc31078_r.jpg?source=1940ef5c",
        name: "燕麦",
        sold: "21",
        originPrice: "99",
        price: "58"
      }
    ],
    navScrollTop: 0,
    searchTop: 9999,
    menuIndex: 0,
    menuTop: 9999,
    searchHeight: 40,
    fixedSearchWidth: util.getFixedSearchWidth()
  },
  /**
   * 选择菜单
   * @param {any} e 
   */
  selectMenu: function (e) {
    const index = e.currentTarget.dataset.index;
    this.setData({
      menuIndex: index
    })
  },

  /**
   * 设置搜索框离顶部的距离
   */
  setSearchTop: function () {
    pageInfo.getElementInfo("search").then(res => {
      this.setData({
        searchTop: res.top
      })
    })
  },

  /**
   * 设置菜单离顶部的距离
   */
  setMenuTop: function () {
    pageInfo.getElementInfo("menu").then(res => {
      this.setData({
        menuTop: res.top
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    pageInfo.setSysInfo(this);
    this.setMenuTop();
    this.setSearchTop();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 监听页面滚动
   * @param {any} e 
   */
  onPageScroll: function (e) {
    const scrollTop = e.scrollTop;
    this.setData({
      navScrollTop: util.getNavScrollTop(scrollTop)
    })
  }
})